package com.weme.common.base

import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.widget.FrameLayout
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar

abstract class BaseBottomDialogFragment : BottomSheetDialogFragment() {

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState)

        dialog.window?.apply {
            // 设置动画
            setWindowAnimations(com.weme.common.R.style.SlideUpAnimation)

            // 设置其他窗口属性（可选）
            // setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)
            // setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        }
        dialog.setOnShowListener {
            // 设置底部弹窗背景透明
            val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
            bottomSheet?.background = ColorDrawable(Color.TRANSPARENT)
        }
        return dialog
    }

    override fun onStart() {
        super.onStart()
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_BAR).init()
    }

}